<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateStage extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('stage', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->default('')->comment('名称');
            $table->integer('match_id')->default(0)->comment('比赛ID');
            $table->integer('rules_id')->default(0)->comment('规则ID');
            $table->json('result')->nullable()->comment('比赛结果');
            $table->tinyInteger('status')->default(0)->comment('状态');
            $table->tinyInteger('type')->default(0)->comment('类型');
            $table->timestamps();
            $table->softDeletes();
        });
        Schema::create('rules', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->default('')->comment('名称');
            $table->json('data')->nullable()->comment('规则内容');
            $table->tinyInteger('status')->default(0)->comment('状态');
            $table->tinyInteger('type')->default(0)->comment('类型');
            $table->timestamps();
            $table->softDeletes();
        });
        Schema::create('stage_report', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->default('')->comment('名称');
            $table->integer('stage')->default(0)->comment('阶段ID');
            $table->integer('user_id')->default(0)->comment('用户ID');
            $table->integer('report_status')->default(0)->comment('报名状态');
            $table->tinyInteger('status')->default(0)->comment('状态');
            $table->tinyInteger('type')->default(0)->comment('类型');
            $table->timestamps();
            $table->softDeletes();
        });
        Schema::table('matches', function (Blueprint $table) {
            $table->integer('rules_id')->default(0)->comment('规则ID');
            $table->json('result')->nullable()->comment('比赛结果');
        });
        Schema::table('users', function (Blueprint $table) {
            $table->integer('win')->default(0)->comment('胜局')->after('score');
            $table->integer('fail')->default(0)->comment('败局')->after('score');
            $table->integer('draw')->default(0)->comment('平局')->after('score');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('stage');
        Schema::dropIfExists('rules');
        Schema::dropIfExists('stage_report');
    }
}
